package cn.tedu._05weibo.base.config;

import cn.tedu._05weibo.base.interceptor.LoginCheckInterceptor;
import cn.tedu._05weibo.base.interceptor.MyInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Slf4j
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    //拦截所有请求
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(new MyInterceptor());
//    }

    //拦截微博模块所有请求
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(new MyInterceptor())
//                .addPathPatterns("/v1/weibo/**");
//    }

    //拦截评论模块除获取评论页表以外的所有请求
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(new MyInterceptor())
//                .addPathPatterns("/v1/comment/**")
//                .excludePathPatterns("/v1/comment/selectByWeiboId");
//    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginCheckInterceptor())
                .addPathPatterns("/v1/weibo/insert","/v1/comment/insert");
    }
}
